<script type="text/javascript" language="javascript" charset="utf-8">
$(".header-con li a").removeClass("open-menu");
$(".header-con li #finance").addClass("open-menu");
</script>
<div class="mask">
</div>
<div class="boxed clearfix">
  <div class="common-tit">
    <h2>财务明细</h2>
    <span>财务管理 > 财务明细</span>
    <%= link_to "添加", new_admin_finance_path, class: 'add-staff' %>
  </div>
  <div class="finance-box">
    <div class="basic">
      <h3>
        <i>资产明细</i>
      </h3>
    </div>
    
    <div class="fi-asbox">
      <ul class="fi-assets">
        <li>
          <span>公司收入总计:</span>
          <em><%= @total_info.total_income %></em>
          <span>元</span>
        </li>
        <li>
          <span>公司课消总计:</span>
          <em><%= @total_info.total_course_reckon %></em>
          <span>元</span>
        </li>
        <li>
          <span>公司支出总计:</span>
          <em><%= @total_info.total_expenditure %></em>
          <span>元</span>
        </li>
        <li>
          <span>公司余额:</span>
          <em><%= @total_info.balance_amonut %></em>
          <span>元</span>
        </li>
      </ul>
    </div>
  </div>
  <!--  -->
  <div class="finance-box">
    <div class="basic">
      <h3>
        <i>月支出明细</i>
        <div class="mar-date">
          <div class="mdate-btn" dateCon="close">
            <strong>2016</strong><b>年</b><em>12</em><b>月</b><i></i>
          </div>
          <div class="time-date">
            <div class="t-tra"></div>
            <div class="t-year">
              <span class="year-l"></span>
              <strong>2016年</strong>
              <span class="year-r"></span>
            </div>
            <div class="t-month">
              <span>1月</span>
              <span>2月</span>
              <span>3月</span>
              <span>4月</span>
              <span>5月</span>
              <span>6月</span>
              <span>7月</span>
              <span>8月</span>
              <span>9月</span>
              <span>10月</span>
              <span>11月</span>
              <span>12月</span>
            </div>
          </div>
        </div>

      </h3>
    </div>
    <div id="<%= "#{controller_name}_#{action_name}_search" %>"  class="market clearfix">
      <%= hidden_field_tag 'search_month',"#{Time.now.strftime("%Y-%m")}"%>
      <div  class="list-box" id="studio_select">
        <div class="downbtn">
          <span data_id="all">所有分店</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">所有分店</li>
          <% @studios.each do |studio| %>
            <li data_id="<%= studio.id %>"><%= studio.name %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box" id="branchType">
        <div class="downbtn">
          <span data_id="all">收支</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">收支</li>
          <li data_id="收入">收入</li>
          <li data_id="支出">支出</li>
        </ul>
      </div>
      <div class="list-box" id="incomeDetail">
        <div class="downbtn">
          <span data_id="all">所有收入</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">所有收入</li>
          <% Finance::INCOME_CATEGORY.each do |key,value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box" id="payDetail">
        <div class="downbtn">
          <span data_id="all">所有支出</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">所有支出</li>
          <% Finance::EXPENSE_CATEGORY.each do |key,value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <% end %>
        </ul>
      </div>
    </div>
    <div class="indi-con finance-table">
      <div class="scrollbox fina-nos" id="<%= "#{controller_name}_#{action_name}_datatable" %>" data_source="/admin/finances.json">
        <table>
          <thead>
            <tr>
              <th class="finan-time">时间</th>
              <th class="finan-bop">收支</th>
              <th class="finan-type">类型</th>
              <th class="finan-money">金额</th>
              <th class="finan-bname">分店名</th>
              <th class="sta-operation">操作</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <!--  -->
  <div class="finance-box">
    <div class="basic">
      <h3 class="fi-nob">
        <i>月支出总结</i>
      </h3>
    </div>
    <div class="indi-con " id="month_blance_table">
      <div class="scrollbox fi-not">
        <table>
          <thead>
            <tr>
              <th class="fina-turnover">本月营业额(元)</th>
              <th class="fina-cf">本月课消(元)</th>
              <th class="fina-course">本月支出(元)</th>
              <th>本月盈亏(元)</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td id="income_amount" >0</td>
              <td id="course_reckon_amount">0</td>
              <td id="expenditure_amount">0</td>
              <td id="gain_loss_amount">0</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

<script src="/assets/js/common-list.js"></script>
<!-- <script>
$(function(){
  $('.date-list1').date_input();
  $(".date-list2").date_input();
});
$('.date-list2').on("click", function() {
   updateT1();
   $('.nav span').on("click", function() {
     if ($(this).parent().parent().parent().prev().attr("class") == "date-list2") {
       updateT1();
     };
   }); 
 });
 $('.date-list1').on("click", function() {
   updateT2();
   $('.nav span').on("click", function() {
     if ($(this).parent().parent().parent().prev().attr("class") == "date-list1") {
       updateT2();
     };
   });
 });
/* 日历  启示日期  结束日期 */
function updateT1() {
  var d = $('.date-list1').val().split("-");
  for (var i = 0; i < d.length; i++) {
    d[i] = Number(d[i]);
  };
  var trs = $('.date-list2').next().children("table").children("tbody").children();
  for (var i = 0; i < trs.length; i++) {
    for (var j = 0, tds = $(trs[i]).children(); j < tds.length; j++) {
      var tDate = $(tds[j]).attr("date").split("-");
      if ($(tds[j]).hasClass("unselected_mon")) {
        $(tds[j]).removeClass("unselected_mon");
      };
      for (var t = 0; t < tDate.length; t++) {
        tDate[t] = Number(tDate[t]);
      };
      if ($('.date-list1').val() != "") {
        if (tDate[0] < d[0] || (tDate[0] == d[0] && tDate[1] < d[1]) || (tDate[0] == d[0] && tDate[1] == d[1] && tDate[2] < d[2])) {
          $(tds[j]).addClass("unselected_mon");
        }
      }
    };
  };
}

function updateT2() {
  var tDate = $('.date-list2').val().split("-");
  for (var i = 0; i < tDate.length; i++) {
    tDate[i] = Number(tDate[i]);
  };
  var trs = $('.date-list1').next().children("table").children("tbody").children();
  for (var i = 0; i < trs.length; i++) {
    for (var j = 0, tds = $(trs[i]).children(); j < tds.length; j++) {
      var d = $(tds[j]).attr("date").split("-");
      if ($(tds[j]).hasClass("unselected_mon")) {
        $(tds[j]).removeClass("unselected_mon");
      };
      for (var t = 0; t < d.length; t++) {
        d[t] = Number(d[t]);
      };
      if ($('.date-list2').val() != "") {
        if (tDate[0] < d[0] || (tDate[0] == d[0] && tDate[1] < d[1]) || (tDate[0] == d[0] && tDate[1] == d[1] && tDate[2] < d[2])) {
        $(tds[j]).addClass("unselected_mon");
        }
      };
    };
  };
}
$("#branchType li").on("click", function() {
  if ($(this).text() == "收入") {
    $("#incomeDetail").css({
      "display" : "block"
    });
    $("#payDetail").css({
      "display" : "none"
    });
  } else if ($(this).text() == "支出") {
    $("#incomeDetail").css({
      "display" : "none"
    });
    $("#payDetail").css({
      "display" : "block"
    });
  } else {
    $("#incomeDetail").css({
      "display" : "none"
    });
    $("#payDetail").css({
      "display" : "none"
    });
  }
});
$(".date-list1").change(function() {
  transData();
});
$(".date-list2").change(function() {
  transData();
});
$(".market .list-box li").on("click", function() {
    $(this).parent().parent().find("span").attr("data_id", $(this).attr("data_id"));
    transData();
  });
 function transData() {
  var transD = "";
  for (var i = 0; i < $(".market .list-box").length; i++) {
    switch(true) {
      case i == 0: transD += "studio_id" + "=" + $($(".market .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 1: transD += "finance_type" + "=" + $($(".market .list-box")[i]).find("span").attr("data_id");break;
    }
  };
  if($($(".market .list-box")[1]).find("span").attr("data_id") == "收入") {
    transD += "&" + "finance_category" + "=" + $($(".market .list-box")[2]).find("span").attr("data_id");
  } else if ($($(".market .list-box")[1]).find("span").attr("data_id") == "支出") {
    transD += "&" + "finance_category" + "=" + $($(".market .list-box")[3]).find("span").attr("data_id");
  }
  if ($(".date-list1").val() == "") {
    transD += "&" + "begin_time" + "=" + "all";
  } else {
    transD += "&" + "begin_time" + "=" + $(".date-list1").val();
  }
  if ($(".date-list2").val() == "") {
    transD += "&" + "end_time" + "=" + "all";
  } else {
    transD += "&" + "end_time" + "=" + $(".date-list2").val();
  }
  // console.log(transD);
  $.ajax({
    type:'get', url:"/admin/finances/get_finance_list?"+ transD,
    success: function(data) {
      if (data.error) {
        // console.log("wrong");
      } 
    }
  });
};
</script>
 -->